/**
 * Created with JetBrains PhpStorm.
 * User: CuongDD5
 * Date: 5/23/13
 * Time: 1:15 PM
 * To change this template use File | Settings | File Templates.
 */
$(window).load(function () {
    $('#slider').nivoSlider();
});

$(function () {
    $("#tabs").tabs();
});

$(document).ready(function () {
    $('#back-top a').click(function () {
        $('body,html').animate({
            scrollTop: 0
        }, 800);
        return false;
    });

    $("a[rel^='prettyPhoto']").prettyPhoto();

    var str = location.href.toLowerCase();
    $("nav ul li a").each(function () {
        if (str.indexOf(this.href.toLowerCase()) > -1) {
            $("li.current-menu-item").removeClass("current-menu-item");
            $(this).parent().addClass("current-menu-item");
        }
    });

    $("li.current-menu-item").parents().each(function () {
        if ($(this).is("li")) {
            $(this).addClass("current-menu-item");
        }
    });

    readCart();
});

function readCart() {
    $.ajax({
        type: "GET",
        url: "checkCart.php",
        cache: false,
        success: function (res) {
            $("#prod-qty").html(res);
        }
    });
}

function addCart(ime, name, price) {
    $.ajax({
        type: "GET",
        url: "addCart.php",
        cache: false,
        data: 'ime=' + ime + '&name=' + name + '&price=' + price,
        success: function (res) {
            showConfirmDialog();
            readCart();
        }
    });
}

function showConfirmDialog() {
    $('#muahang').html("Sản phẩm đã được thêm vào giỏ hàng");
    $( "#muahang" ).fadeIn('slow');
    $( "#muahang" ).fadeOut('slow');
    /*
    $("#dialog").dialog(
        {
            width: 300,
            height: 160,
            modal: true,
            buttons: {
                "Đóng": function () {
                    $(this).dialog("close");
                }
            }
        });
*/
    return false;
}